package com.union.core.workModel.service;

import java.io.File;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.union.core.workModel.dao.ModelBonusDao;
import com.union.core.workModel.dao.ModelIncomDao;
import com.union.core.workModel.dao.ModelInfoDao;
import com.union.core.workModel.dao.ModelMemberDao;
import com.union.core.workModel.dao.impl.ModelBonusDaoImpl;
import com.union.core.workModel.dao.impl.ModelIncomDaoImpl;
import com.union.core.workModel.dao.impl.ModelInfoDaoImpl;
import com.union.core.workModel.dao.impl.ModelMemberDaoImpl;
import com.union.core.workModel.model.ModelBonus;
import com.union.core.workModel.model.ModelIncom;
import com.union.core.workModel.model.ModelInfo;
import com.union.core.workModel.model.ModelMember;

public class ModelInfoService {
	private ModelInfoDao modelInfoDaoImpl;
	private ModelIncomDao modelIncomDaoImpl;
	private ModelMemberDao modelMemberDaoImpl;
	private ModelBonusDao modelBonusDaoImpl;
	private static Logger log = Logger.getLogger(ModelInfoService.class.getName());
	public ModelInfoService(){
		modelInfoDaoImpl=new ModelInfoDaoImpl();
		modelIncomDaoImpl=new ModelIncomDaoImpl();
		modelMemberDaoImpl=new ModelMemberDaoImpl();
		modelBonusDaoImpl=new ModelBonusDaoImpl();
	}
	/**
	 * 查询：劳模列表
	 * @param sex
	 * @param honour
	 * @param level
	 * @param current
	 * @param paramName
	 * @param paramValue
	 * @param orderByName
	 * @param start
	 * @param intPageSize
	 * @return
	 */
	public List<ModelInfo> queryList(int sex,String honour,String level,
			String current,String paramName,String paramValue,
			String orderByName,int start,int intPageSize){
		return modelInfoDaoImpl.queryModelList(sex, honour, level, current,
				paramName, paramValue, orderByName, start, intPageSize);
	}
	/**
	 * 查询：劳模列表数量
	 * @param sex
	 * @param honour
	 * @param level
	 * @param current
	 * @param paramName
	 * @param paramValue
	 * @return
	 */
	public int queryListCount(int sex,String honour,String level,
			String current,String paramName,String paramValue){
		return modelInfoDaoImpl.queryModelListCount(sex, honour, level, 
				current, paramName, paramValue);
	}
	/**
	 * 查询：单条劳模信息
	 * @param model_id
	 * @return
	 */
	public ModelInfo queryModelById(int model_id){
		//劳模收入记录
		List<ModelIncom> incomList=modelIncomDaoImpl.queryIncomList(model_id, 1);
		//劳模补助记录
		List<ModelIncom> buzhuList=modelIncomDaoImpl.queryIncomList(model_id, 2);
		//劳模成员记录
		List<ModelMember> memberList=modelMemberDaoImpl.queryMemberList(model_id);
		ModelInfo mif=modelInfoDaoImpl.queryModelById(model_id);
		mif.setIncomList(incomList);
		mif.setBuzhuList(buzhuList);
		mif.setMemberList(memberList);
		return mif;
	}
	/**
	 * 添加：劳模信息
	 * @param model
	 * @return
	 */
	public int addModel(ModelInfo model){
		return modelInfoDaoImpl.addModel(model);
	}
	/**
	 * 修改：劳模信息
	 * @param model
	 * @return
	 */
	public boolean editModel(ModelInfo model){
		return modelInfoDaoImpl.editModel(model);
	}
	/**
	 * 删除：劳模信息
	 * @param model
	 * @return
	 */
	public boolean delModel(int model_id){
		//搜索劳模对应头像位置
		ModelInfo mif=modelInfoDaoImpl.queryModelById(model_id);
		String img=mif.getModel_image();
		if(!"".equals(img) && null!=img){
		//删除头像
			String sDirPath1 = ServletActionContext.getServletContext().getRealPath("/");
			String p=sDirPath1+img;
			File fl=new File(p);
			fl.delete();
		}
		//删除对应收入、成员、奖金记录
		modelIncomDaoImpl.delIncomList(model_id);
		modelMemberDaoImpl.delMemberList(model_id);
		modelBonusDaoImpl.delBonusList(model_id);
		return modelInfoDaoImpl.delModel(model_id);
	}
	/**
	 * 查询：劳模收入记录集
	 * @param modelId
	 * @param type
	 * @return
	 */
	public List<ModelIncom> queryIncomList(int modelId,int type){
		return modelIncomDaoImpl.queryIncomList(modelId, type);
	}
	/**
	 * 查询：单条劳模收入记录
	 * @param incomId
	 * @return
	 */
	public ModelIncom queryIncomByid(int incomId){
		return modelIncomDaoImpl.queryById(incomId);
	}
	/**
	 * 添加：劳模收入记录
	 * @param modelIncom
	 * @return
	 */
	public boolean addIncom(ModelIncom modelIncom){
		return modelIncomDaoImpl.addIncom(modelIncom);
	}
	/**
	 * 修改：劳模收入记录
	 * @param modelIncom
	 * @return
	 */
	public boolean editIncom(ModelIncom modelIncom){
		return modelIncomDaoImpl.editIncom(modelIncom);
	}
	/**
	 * 删除：劳模收入记录
	 * @param incomId
	 * @return
	 */
	public boolean delIncom(int incomId){
		return modelIncomDaoImpl.delIncom(incomId);
	}
	/**
	 * 查询：劳模家庭成员记录集
	 * @param modelId
	 * @return
	 */
	public List<ModelMember> queryMemberList(int modelId){
		return modelMemberDaoImpl.queryMemberList(modelId);
	}
	/**
	 * 查询：单条劳模家庭成员记录
	 * @param memberId
	 * @return
	 */
	public ModelMember queryMemberById(int memberId){
		return modelMemberDaoImpl.queryById(memberId);
	}
	/**
	 * 添加：劳模家庭成员记录
	 * @param modelMember
	 * @return
	 */
	public boolean addMember(ModelMember modelMember){
		return modelMemberDaoImpl.addMember(modelMember);
	}
	/**
	 * 修改：劳模家庭成员记录
	 * @param modelMember
	 * @return
	 */
	public boolean editMember(ModelMember modelMember){
		return modelMemberDaoImpl.editMember(modelMember);
	}
	/**
	 * 删除：劳模家庭成员记录
	 * @param memberId
	 * @return
	 */
	public boolean delMember(int memberId){
		return modelMemberDaoImpl.delMember(memberId);
	}
	/**
	 * 查询：劳模援助金记录集
	 * @param modelId
	 * @return
	 */
	public List<ModelBonus> queryBonusList(int modelId){
		return modelBonusDaoImpl.queryBonusList(modelId);
	}
	/**
	 * 查询：单条劳模援助金记录
	 * @param bonusId
	 * @return
	 */
	public ModelBonus queryBonusById(int bonusId){
		return modelBonusDaoImpl.queryById(bonusId);
	}
	/**
	 * 添加：劳模援助金记录
	 * @param modelMember
	 * @return
	 */
	public boolean addBonus(ModelBonus modelBonus){
		return modelBonusDaoImpl.addBonus(modelBonus);
	}
	/**
	 * 修改：劳模援助金记录
	 * @param modelBonus
	 * @return
	 */
	public boolean editBonus(ModelBonus modelBonus){
		return modelBonusDaoImpl.editBonus(modelBonus);
	}
	/**
	 * 删除：劳模援助金记录
	 * @param bonusId
	 * @return
	 */
	public boolean delBonus(int bonusId){
		return modelBonusDaoImpl.delBonus(bonusId);
	}
	/**
	 * 删除：根据劳模id删除所有对应收入记录
	 * @param modelId
	 * @return
	 */
	public boolean delIncomList(int modelId){
		return modelIncomDaoImpl.delIncomList(modelId);
	}
	/**
	 * 删除：根据劳模id删除所有对应成员记录
	 * @param modelId
	 * @return
	 */
	public boolean delMemberList(int modelId){
		return modelMemberDaoImpl.delMemberList(modelId);
	}
	/**
	 * 删除：根据劳模id删除所有对应援助金记录
	 * @param modelId
	 * @return
	 */
	public boolean delBonusList(int modelId){
		return modelBonusDaoImpl.delBonusList(modelId);
	}
	
}
